package com.liming;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("肖博文");
        arrayList.add("肖博文");
        arrayList.add("肖博文");
        System.out.println(arrayList);

        ArrayList<String> list = new ArrayList<>((new HashSet<String>(arrayList)));
        System.out.println(list);
        System.out.println("------------------------");
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("肖博文");
        hashSet.add("萧炎");
        hashSet.add("唐三");
        hashSet.add("小舞");
        hashSet.add("荒天帝");
        System.out.println(hashSet);
        //取数据(迭代器)
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            System.out.println(s);
        }
        //增强for循环
        for (String s : hashSet) {
            System.out.println("name :" +s);
        }
        int [] arr = {0,1,2,3,4,5,6,7,8,9};
        for (int i: arr) {
            System.out.println(i);
        }
        //lambda表达式
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        hashSet.forEach(System.out::println);
        Student student = new Student("肖博文",20,"男","123456");
        System.out.println(student);
    }
}
